package com.yfp.client.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.client.domain.ActivitySignInsClients;
import com.yfp.client.mapper.ActivitySignInsClientsMapper;
import com.yfp.client.service.ActivitySignInsClientsService;
import com.yfp.client.util.SecurityUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @description 针对表【activity_sign_ins_clients(打卡管理-参与用户表)】的数据库操作Service实现
 * @createDate 2025-01-03 17:46:13
 */
@Service
public class ActivitySignInsClientsServiceImpl extends ServiceImpl<ActivitySignInsClientsMapper, ActivitySignInsClients> implements ActivitySignInsClientsService {

    @Resource
    private ActivitySignInsClientsMapper activitySignInsClientsMapper;

    @Override
    public void joinActivity(Long activitySignInsId) {
        String clientId = SecurityUtils.getClientId();

        ActivitySignInsClients activitySignInsClients = new ActivitySignInsClients();
        activitySignInsClients.setActivitySignInsId(activitySignInsId);
        activitySignInsClients.setClientId(clientId);
        activitySignInsClients.setCreateTime(DateUtil.date());
        activitySignInsClients.setTotalSignIn(0);

        activitySignInsClientsMapper.insert(activitySignInsClients);
    }

    @Override
    public Boolean joined(Long activitySignInsId) {
        String clientId = SecurityUtils.getClientId();

        ActivitySignInsClients activitySignInsClients = new ActivitySignInsClients();
        activitySignInsClients.setActivitySignInsId(activitySignInsId);
        activitySignInsClients.setClientId(clientId);

        List<ActivitySignInsClients> activitySignInsClientsList = activitySignInsClientsMapper.selectByReq(activitySignInsClients);
        return CollUtil.isNotEmpty(activitySignInsClientsList);
    }

    @Override
    public ActivitySignInsClients getByClientAndId(Long activitySignInsId) {
        String clientId = SecurityUtils.getClientId();

        ActivitySignInsClients activitySignInsClients = new ActivitySignInsClients();
        activitySignInsClients.setActivitySignInsId(activitySignInsId);
        activitySignInsClients.setClientId(clientId);

        List<ActivitySignInsClients> activitySignInsClientsList = activitySignInsClientsMapper.selectByReq(activitySignInsClients);
        return CollUtil.getFirst(activitySignInsClientsList);
    }
}




